//
//  FilterViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/10/23.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "FilterViewController.h"
#import "FPNumberPadView.h"
#import "FilterTableViewCell.h"

@interface FilterViewController ()<FPNumberPadViewDelegate>
{
    
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *filterTypeNameArray ;
    
    NSMutableArray *filterAllTypeCodeArray ;
    NSMutableArray *filterAllTypeNameArray ;
    
    NSMutableArray *filterCodeArray;
    NSMutableArray *filterNameArray;
    
    NSMutableArray *filterDefaultArray;
    
    
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputFilterNameArray;
    
    
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSInteger selectFilterTypeTag;
    NSMutableArray *selectFilterCodeArray;
   
    UITextField *inputTextField;
    NSMutableArray *selectFilterTextArray;
//    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    
    NSString *dateStr;
    NSString *leftLabelStr;
    NSInteger rightTag;
    
    NSInteger buttonTag;
    
    NSMutableArray *tableFilterCodeArray;
    NSMutableArray *tableFilterNameArray;
    
   // NSString *isDefault;

}
@end

@implementation FilterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self initOrderFilterView];
}
-(void)initOrderFilterView
{
    tableFilterCodeArray=[NSMutableArray array];
    tableFilterNameArray=[NSMutableArray array];
    
    inputFilterCodeArray=[NSMutableArray array];
    inputFilterNameArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    CGRect frame=_dateView.frame;
    frame.origin.y=768;
    _dateView.frame=frame;
    
    CGRect frame1=_tableViewViewContainer.frame;
    frame1.origin.y=768;
    _tableViewViewContainer.frame=frame1;
    
    _isDefault=@"Y";
   
    leftLabelStr=@"";
   dateStr=[NSString stringWithFormat:@"%@~%@",_startTimeStr,_endTimeStr];
    rightTag=0;
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    filterTypeNameArray=[NSMutableArray array];
    filterCodeArray=[NSMutableArray array];
    filterNameArray=[NSMutableArray array];
    filterAllTypeCodeArray=[NSMutableArray array];
    filterAllTypeNameArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
//    selectFilterNameArray=[NSMutableArray array];
   // selectCustomTimeArray=[NSMutableArray array];
    filterDefaultArray=[NSMutableArray array];
    selectFilterTextArray=[NSMutableArray array];
    [_tableAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];

    [_orderFilterAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_orderFilterAlphaView addTarget:self action:@selector(orderFilterAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    [self requestOrderFilter];
   
}
-(void)requestOrderFilter
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:@"" forKey:@"FilterType"];
        [params setObject:_docTypeStr forKey:@"FilterBusType"];
        //[params setObject:_searchMemberTextField.text forKey:@"KeyWord"];
        
        [HttpRequest requestData:@"Common/AdvancedFilterList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                   
                    NSMutableArray *dataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    NSMutableArray *inputDataLineArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine2"]];
                    [inputFilterNameArray removeAllObjects];
                    [inputFilterCodeArray removeAllObjects];
                    [customTimeFilterTypeCodeArray removeAllObjects];
                    for (int i=0; i<dataLineArray.count; i++) {
                        if(![filterTypeCodeArray containsObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]])
                        {
                            [filterTypeCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]];
                            [filterTypeNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterTypeName"]];
                            [filterDefaultArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterName"]];
                        }
                        
                        [filterCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterCode"]];
                        [filterNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterName"]];
                        [filterAllTypeCodeArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]];
                        [filterAllTypeNameArray addObject:[[dataLineArray objectAtIndex:i] objectForKey:@"FilterTypeName"]];
                        
                        
                    }
                    
                    for (int i=0; i<inputDataLineArray.count; i++) {
                        if ([[[inputDataLineArray objectAtIndex:i] objectForKey:@"DataType"] isEqualToString:@"Date"]) {
                            if(![customTimeFilterTypeCodeArray  containsObject:[[inputDataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]])
                            {
                                [customTimeFilterTypeCodeArray addObject:[[inputDataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]];
                                
                            }
                            
                        }
                        else
                        {
                            [inputFilterCodeArray addObject:[[inputDataLineArray objectAtIndex:i] objectForKey:@"FilterTypeCode"]];
                            [inputFilterNameArray addObject:[[inputDataLineArray objectAtIndex:i] objectForKey:@"FilterTypeName"]];
                        }
                    }

                    [self setInputOrderFilter];
                    [self setOrderFilterTypeView];
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    //                    UIViewController *controller=[[GlobalViewController alloc]init];
                    //                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
-(void)setInputOrderFilter
{
    for (int i=0; i<inputFilterCodeArray.count; i++) {
        
        UILabel *leftTextLabel=[[UILabel alloc] init];
        
        CGRect rect=leftTextLabel.frame;
        rect.size.height=20;
        rect.size.width=100;
        rect.origin.x=60;
        rect.origin.y=18+60*i;
        leftTextLabel.frame=rect;
        
        [leftTextLabel setText:[inputFilterNameArray objectAtIndex:i]];
        [leftTextLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
        [leftTextLabel setBackgroundColor:[UIColor clearColor]];
        [_inputFilterView addSubview:leftTextLabel];
        
        
        UITextField *minTextfield=[[UITextField alloc] init];
       
        CGRect minRect=minTextfield.frame;
        minRect.size.height=20;
        minRect.size.width=100;
        minRect.origin.x=141;
        minRect.origin.y=18+60*i;
        minTextfield.frame=minRect;
        minTextfield.tag=500+i;
        [minTextfield setTextAlignment:NSTextAlignmentCenter];
        
        FPNumberPadView *numberPadView1 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
      //  numberPadView1.FPNumberPaddelegate=self;
        numberPadView1.textField = minTextfield;
        
        
        NSString *minStr=@"";
        // NSLog(@"inputFilterCodeArray[%d]===%@",i,[inputFilterCodeArray objectAtIndex:i ]);
        if (inputMinResultFilterNameArray.count>0&&[[inputMinResultFilterNameArray objectAtIndex:i] floatValue]>0) {
            minStr=[inputMinResultFilterNameArray objectAtIndex:i];
        }
        else
        {
            minStr=[NSString stringWithFormat:@"最小%@",[inputFilterNameArray objectAtIndex:i]];
        }
        
        [minTextfield setPlaceholder:minStr];
        [_inputFilterView addSubview:minTextfield];
        
        UILabel *midLabel=[[UILabel alloc] init];
        
        CGRect midRect=midLabel.frame;
        midRect.size.height=20;
        midRect.size.width=22;
        midRect.origin.x=259;
        midRect.origin.y=18+60*i;
        midLabel.frame=midRect;
        
        [midLabel setText:@"~"];
        [midLabel setFont:[UIFont fontWithName:@"Helvetica" size:15]];
        [midLabel setBackgroundColor:[UIColor clearColor]];
        [_inputFilterView addSubview:midLabel];
        
        UITextField *maxTextfield=[[UITextField alloc] init];
        
        CGRect maxRect=maxTextfield.frame;
        maxRect.size.height=20;
        maxRect.size.width=162;
        maxRect.origin.x=316;
        maxRect.origin.y=18+60*i;
        maxTextfield.frame=maxRect;
        maxTextfield.tag=600+i;
        [maxTextfield setTextAlignment:NSTextAlignmentLeft];
        
        NSString *maxStr=@"";
        
        if (inputMaxResultFilterNameArray.count>0&&[[inputMaxResultFilterNameArray objectAtIndex:i] floatValue]>0) {
            maxStr=[inputMaxResultFilterNameArray objectAtIndex:i];
        }
        else
        {
            maxStr=[NSString stringWithFormat:@"最大%@",[inputFilterNameArray objectAtIndex:i]];
        }
        [maxTextfield setPlaceholder:maxStr];
        FPNumberPadView *numberPadView2 = [[FPNumberPadView alloc] initWithFrame:CGRectMake(0, 0, 948, 340)];
        numberPadView2.FPNumberPaddelegate=self;
        numberPadView2.textField = maxTextfield;
        
        [_inputFilterView addSubview:maxTextfield];
        
        UILabel *lineLabel=[[UILabel alloc] init];
        
        CGRect lineRect=lineLabel.frame;
        lineRect.size.height=1;
        lineRect.size.width=545;
        lineRect.origin.x=35;
        lineRect.origin.y=55+60*i;
        lineLabel.frame=lineRect;
        
        
        [lineLabel setBackgroundColor:[UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0f]];
        [_inputFilterView addSubview:lineLabel];
        
    }
    CGRect frame=_inputFilterView.frame;
    frame.size.height=60*inputFilterCodeArray.count;
    _inputFilterView.frame=frame;
    
    CGRect frameA=_orderFilterMainView.frame;
    frameA.origin.y=_inputFilterView.frame.origin.y+_inputFilterView.frame.size.height;
    _orderFilterMainView.frame=frameA;
   

}
-(void)setOrderFilterTypeView
{
    [selectFilterCodeArray removeAllObjects];
    for (int i=0; i<filterTypeCodeArray.count; i++) {
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        CGRect rect=button.frame;
        rect.size.height=60;
        rect.size.width=545;
        rect.origin.x=35;
        rect.origin.y=60*i;
        button.frame=rect;
        button.tag=i;
        [button setBackgroundColor:[UIColor clearColor]];
        [button setTitleColor:[UIColor clearColor] forState:UIControlStateNormal ];
        //[button setTintColor:[UIColor clearColor]];
        [button setTitle:[filterTypeNameArray objectAtIndex:i] forState:UIControlStateNormal];
        UILabel *leftTextLabel=[[UILabel alloc] initWithFrame:CGRectMake(25, 20, 100, 20)];
        leftTextLabel.tag=8000+i;
        [leftTextLabel setText:[filterTypeNameArray objectAtIndex:i]];
        [leftTextLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
        [leftTextLabel setBackgroundColor:[UIColor clearColor]];
        [button addSubview:leftTextLabel];
        
        UILabel *rightTextLabel=[[UILabel alloc] initWithFrame:CGRectMake(480, 20, 100, 20)];
       
        if ([leftTextLabel.text isEqualToString:@"时间"]) {
            
            if (_selectCustomTimeArray.count>0) {
                [rightTextLabel setText:[_selectCustomTimeArray objectAtIndex:0]];
            }
            else
            {
                if (_selectFilterNameArray.count>0) {
                    [rightTextLabel setText:[_selectFilterNameArray objectAtIndex:i]];
                }
                else
                {
                    [rightTextLabel setText:[filterDefaultArray objectAtIndex:i]];
                }
                NSInteger rightTextTag=[filterNameArray indexOfObject:rightTextLabel.text];
                NSString *rightTextCodeStr=[filterCodeArray objectAtIndex:rightTextTag];
                [selectFilterCodeArray addObject:rightTextCodeStr];
                
            }
        }
        else
        {
            if (_selectFilterNameArray.count>0) {
                [rightTextLabel setText:[_selectFilterNameArray objectAtIndex:i]];
            }
            else
            {
                [rightTextLabel setText:[filterDefaultArray objectAtIndex:i]];
            }
            NSInteger rightTextTag=[filterNameArray indexOfObject:rightTextLabel.text];
            NSString *rightTextCodeStr=[filterCodeArray objectAtIndex:rightTextTag];
            [selectFilterCodeArray addObject:rightTextCodeStr];
        }
        rightTextLabel.tag=900+i;
        if([leftTextLabel.text isEqualToString:@"时间"])
        {
            _customSureBtn.tag=rightTextLabel.tag;
        }
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(495, 16, 30, 30)];
        img.tag=2000+i;
        [img setImage:[UIImage imageNamed:@"jiantou_down.png"]];
        [button addSubview:img];
        
        rightTextLabel.textColor=[UIColor colorWithRed:210.0f/255.0f green:171.0f/255.0f blue:57.0f/255.0f alpha:1.0f];
        [rightTextLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
        [rightTextLabel setBackgroundColor:[UIColor clearColor]];
        [button addSubview:rightTextLabel];
        
        [Global resizeForLable:rightTextLabel WithText:rightTextLabel.text parentView:self.view];
        CGRect frameK=rightTextLabel.frame;
        frameK.origin.x=img.frame.origin.x-frameK.size.width-5;
        rightTextLabel.frame=frameK;
        
        
        
        UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 59, 545, 1)];
        // NSLog(@"lineLabel.origin.y ==%f",lineLabel.frame.origin.y);
        [lineLabel setBackgroundColor:[UIColor colorWithRed:241.0f/255.0f green:241.0f/255.0f blue:241.0f/255.0f alpha:1.0f]];
        [button addSubview:lineLabel];
        
        [button addTarget:self action:@selector(selectFilterBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [_orderFilterMainView addSubview:button];
        //        CGRect buttonFrame=_confirmFilterBtn.frame;
        float height=_inputFilterView.frame.origin.y+_inputFilterView.frame.size.height+60*filterTypeCodeArray.count+30;
        //        _confirmFilterBtn.frame=buttonFrame;
        
        [_orderFilterMainView setContentSize:CGSizeMake(0, height+40)];
        //  NSLog(@"frame gggg= %f",htmlHeight);
        [_orderFilterMainView setShowsVerticalScrollIndicator:NO];
        [_orderFilterMainView setScrollEnabled:YES];
        
        // [_orderFilterViewContainer bringSubviewToFront:_confirmFilterBtn];
        
    }
    [_orderFilterMainView setContentSize:CGSizeMake(0, 60*filterTypeCodeArray.count+10)];
    [_orderFilterMainView setShowsVerticalScrollIndicator:NO];
    [_orderFilterMainView setScrollEnabled:YES];

}
-(void)selectFilterBtn:(UIButton *)sender
{
    //
    buttonTag=sender.tag;
    NSString *typeNameStr=sender.titleLabel.text;
  
    [tableFilterCodeArray removeAllObjects];
    [tableFilterNameArray removeAllObjects];
    for (int i=0; i<filterAllTypeNameArray.count; i++) {
        
        if ([[filterAllTypeNameArray objectAtIndex:i] isEqualToString:typeNameStr]) {
            [tableFilterNameArray addObject:[filterNameArray objectAtIndex:i]];
            
        }
    }
    [_filterTableView reloadData];
    UILabel *rightTextLabel=(UILabel *)[sender viewWithTag:900+buttonTag] ;
    
    //        if (_customSureBtn.tag!=100000) {
    
    NSInteger index= [tableFilterNameArray indexOfObject:rightTextLabel.text];
    // if (index!=NSNotFound) {
    rightTag=index;
   // NSLog(@"rightTag==%d",rightTag);
    NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:rightTag inSection:0];
    UITableViewCell *cell = [_filterTableView cellForRowAtIndexPath:indexPath1];
    FilterTableViewCell *filterCell=( FilterTableViewCell *)cell;
    filterCell.iconImageView.hidden=NO;
    
    _customEndTime.text=_endTimeStr;
    _customStartTime.text=_startTimeStr;
    leftLabelStr=typeNameStr;
    

    if([typeNameStr isEqualToString:@"时间"])
    {
        _customTimeView.hidden=NO;
        
        CGRect framea = _customTimeView.frame;
        framea.origin.y= _filterTableView.frame.origin.y+55*tableFilterNameArray.count+1;
        _customTimeView.frame = framea;
        
    }
    else
    {
        _customTimeView.hidden=YES;
    }
    
    _filterTitleLabel.text=typeNameStr;
    
    
    CGRect frame = _tableViewViewContainer.frame;
    frame.origin.y = 0;
    _tableViewViewContainer.frame = frame;
    
}
-(IBAction)resetFilterBtnClick:(id)sender
{
    _startTimeStr=@"";
    _endTimeStr=@"";
    _customStartTime.text=@"";
    _customEndTime.text=@"";
    dateStr=@"";
    _isDefault=@"Y";
    [_selectFilterNameArray removeAllObjects];
    [_selectCustomTimeArray removeAllObjects];
    [selectFilterCodeArray removeAllObjects];
    [filterTypeCodeArray removeAllObjects];
    [customTimeFilterTypeCodeArray removeAllObjects];
    [filterTypeNameArray removeAllObjects];
    [filterCodeArray removeAllObjects];
    [filterNameArray removeAllObjects];
    [filterAllTypeCodeArray removeAllObjects];
    [filterAllTypeNameArray removeAllObjects];
    for (UIView *v in _orderFilterMainView.subviews) {
        if (v.tag!=10000) {
            [v removeFromSuperview];
        }
    }
    [self requestOrderFilter];
}

-(IBAction)customTimeSureBtnClick:(UIButton *)sender
{
    
   // customDateStr=[NSString stringWithFormat:@"%@~%@",_customStartTime.text,_customEndTime.text];//@"自定义";
     dateStr=[NSString stringWithFormat:@"%@~%@",_customStartTime.text,_customEndTime.text];//@"自定义";
    //    [selectFilterNameArray addObject:dateStr];
    //    [selectFilterTextArray addObject:dateStr];
    _startTimeStr=_customStartTime.text;
    _endTimeStr=_customEndTime.text;
    
    UILabel *rightTextLabel=(UILabel *)[_orderFilterMainView viewWithTag:900+buttonTag] ;
    rightTextLabel.text=dateStr;
    
    [Global resizeForLable:rightTextLabel WithText:rightTextLabel.text parentView:self.view];
    CGRect frameK=rightTextLabel.frame;
    frameK.origin.x=495-frameK.size.width-5;
    rightTextLabel.frame=frameK;

    
    CGRect frame = _tableViewViewContainer.frame;
    frame.origin.y = 768;
    _tableViewViewContainer.frame = frame;
    
}

-(IBAction)dateViewConfirmClick:(id)sender
{
    //NSLog(@"curDate is %@" ,selectedDate);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //修改时区为东8区
    
    NSString *destDateString =@"";
    if (inputTextField==_customStartTime) {
        NSDate *selectedDate =[_datePicker date];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_dateView.frame;
             viewFrame.origin.y=768;
             _dateView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
        
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        destDateString = [dateFormatter stringFromDate:selectedDate];
        _customStartTime.text=destDateString;
        
    }
    else if (inputTextField==_customEndTime)
    {
        NSDate *selectedDate =[_datePicker date];
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_dateView.frame;
             viewFrame.origin.y=768;
             _dateView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
             
         }];
        
        
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        destDateString = [dateFormatter stringFromDate:selectedDate];
        _customEndTime.text=destDateString;
        
    }
    
}
-(IBAction)confirmFilterClick:(id)sender
{
    [_orderFilterMainView setContentOffset:CGPointMake(0, 0)];
    [_selectFilterNameArray removeAllObjects];
    [selectFilterCodeArray removeAllObjects];
    [_selectCustomTimeArray removeAllObjects];
    
    [inputMinResultFilterNameArray removeAllObjects];
    
    [inputMaxResultFilterNameArray removeAllObjects];
    for (int i=0; i<filterTypeCodeArray.count; i++) {
        UIButton *button=(UIButton *)[_orderFilterMainView viewWithTag:i];
        UILabel *label=(UILabel *)[button viewWithTag:900+i];
       
        // if ([label.text isEqualToString:@"自定义"]) {
        if ([label.text isEqualToString:dateStr]) {
            [_selectCustomTimeArray addObject:dateStr];
            [selectFilterCodeArray addObject:@""];
            [_selectFilterNameArray addObject:@""];
            
        }
        else
        {
            int rightTextTag=[filterNameArray indexOfObject:label.text];
          
            // NSLog(@"rightTextTag===%d",rightTextTag);
            NSString *rightTextCodeStr=[filterCodeArray objectAtIndex:rightTextTag];
            
            [selectFilterCodeArray addObject:rightTextCodeStr];
            
            [_selectFilterNameArray addObject:label.text];
        }
        
    }
    for (int i=0; i<inputFilterCodeArray.count; i++) {
        UITextField *minTextField=(UITextField *)[_inputFilterView viewWithTag:500+i];
        
        //  if ([minTextField.text floatValue]>=0) {
        [inputMinResultFilterNameArray addObject:minTextField.text];
        
        //  }
        
        UITextField *maxTextField=(UITextField *)[_inputFilterView viewWithTag:600+i];
        
        // if ([maxTextField.text floatValue]>=0&&maxTextField.text.length>0) {
        [inputMaxResultFilterNameArray addObject:maxTextField.text];
        
        // }
        
    }
    if (self.view!=nil) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        
    }
    for (int i=0; i<_selectFilterNameArray.count; i++) {
        if (![[_selectFilterNameArray objectAtIndex:i] isEqualToString:[filterDefaultArray objectAtIndex:i]]) {
            _isDefault=@"N";
        }
    }
    for (int i=0; i<inputMinResultFilterNameArray.count; i++)
    {
        
        if ([[inputMinResultFilterNameArray objectAtIndex:i] floatValue]>0) {
            _isDefault=@"N";
        }
        
    }
    for (int i=0; i<inputMaxResultFilterNameArray.count; i++)
    {
        if ([[inputMaxResultFilterNameArray objectAtIndex:i] floatValue]>0) {
            _isDefault=@"N";
        }
    }
    

  //  NSLog(@"_isDefault===%@",_isDefault);
    if ([self.delegate respondsToSelector:@selector(confirmFilterBtnClick:commonSelectFilterCodeArray:commonInputFilterCodeArray:commonInputMinResultFilterNameArray:commonInputMaxResultFilterNameArray:commonCustomTimeFilterTypeCodeArray:commonSelectCustomTimeArray:commonSelectFilterNameArray:commonStartTimeStr:commonEndTimeStr:isDefault:)]) {
        
        [self.delegate confirmFilterBtnClick:filterTypeCodeArray commonSelectFilterCodeArray:selectFilterCodeArray commonInputFilterCodeArray:inputFilterCodeArray commonInputMinResultFilterNameArray:inputMinResultFilterNameArray commonInputMaxResultFilterNameArray:inputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:customTimeFilterTypeCodeArray commonSelectCustomTimeArray:_selectCustomTimeArray commonSelectFilterNameArray:_selectFilterNameArray commonStartTimeStr:_startTimeStr commonEndTimeStr:_endTimeStr isDefault:_isDefault];
        
         }

   
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return tableFilterNameArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 55;
    
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * const  FilterTableViewCellIdentifier = @"FilterTableViewCellIdentifier";
    FilterTableViewCell *cell=( FilterTableViewCell *)[tableView dequeueReusableCellWithIdentifier: FilterTableViewCellIdentifier];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FilterTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
        //  cell.delegate=self;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    if (tableFilterNameArray.count>0) {
        cell.contentLabel.text=[tableFilterNameArray objectAtIndex:indexPath.row];
    }
    return cell;
    
    
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UILabel *rightTextLabel=(UILabel *)[_orderFilterMainView viewWithTag:900+buttonTag] ;
    if ([leftLabelStr isEqualToString:@"时间"]&&[rightTextLabel.text isEqualToString:dateStr] ) {
        _startTimeStr=@"";
        _endTimeStr=@"";
        _customStartTime.text=@"";
        _customEndTime.text=@"";
    }

    rightTextLabel.text=[tableFilterNameArray objectAtIndex:indexPath.row];
    
    [Global resizeForLable:rightTextLabel WithText:rightTextLabel.text parentView:self.view];
    CGRect frameK=rightTextLabel.frame;
    frameK.origin.x=495-frameK.size.width-5;
    rightTextLabel.frame=frameK;

    
    CGRect frame = _tableViewViewContainer.frame;
    frame.origin.y = 768;
    _tableViewViewContainer.frame = frame;
    
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if ([textField isEqual:_customStartTime]||[textField isEqual:_customEndTime]) {
        inputTextField=textField;
        [UIView animateWithDuration:0.5f animations:^
         {
             CGRect viewFrame=_dateView.frame;
             viewFrame.origin.y=0;
             _dateView.frame=viewFrame;
         }completion:^(BOOL finished) {
             
         }];
        return NO;
        
    }
    return YES;
    
}
-(void)keyBordDoneClick
{
   
    for (int i=0; i<inputFilterCodeArray.count; i++) {
        
        UITextField *minTextField=(UITextField *)[_inputFilterView viewWithTag:500+i];
        
        
        UITextField *maxTextField=(UITextField *)[_inputFilterView viewWithTag:600+i];
        
        if ([maxTextField.text floatValue]>=[minTextField.text floatValue]) {
            //isRequest=YES;
        }
        else
        {
            minTextField.text=@"";
            maxTextField.text=@"";
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"最大值需大于等于最小值，请重新填写" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        
        
    }
}


-(IBAction)tableAlphaViewClick:(id)sender
{
    [UIView animateWithDuration:0.5f animations:^
     {
         CGRect viewFrame=_tableViewViewContainer.frame;
         viewFrame.origin.y=768;
         _tableViewViewContainer.frame=viewFrame;
     }completion:^(BOOL finished) {
         
     }];

}
-(void)orderFilterAlphaViewClick
{
    if (self.view!=nil) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
